package com.github.lyd.admin.provider.controller;

import com.github.lyd.admin.provider.entity.WxUserInfoEntity;
import com.github.lyd.admin.provider.service.WxUserInfoService;
import com.github.lyd.admin.provider.utils.PageUtils;
import com.github.lyd.admin.provider.utils.R;
import com.github.lyd.admin.provider.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 微信用户信息
 *
 * @author yaowu
 * @email toyaowu@163.com
 * @date 2019-01-20 11:08:15
 */
@RestController
@RequestMapping("weixin/wxuserinfo")
public class WxUserInfoController {
    @Autowired
    private WxUserInfoService wxUserInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wxUserInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{openId}")
    public R info(@PathVariable("openId") String openId){
        WxUserInfoEntity wxUserInfo = wxUserInfoService.selectById(openId);

        return R.ok().put("wxUserInfo", wxUserInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WxUserInfoEntity wxUserInfo){
        wxUserInfoService.insert(wxUserInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WxUserInfoEntity wxUserInfo){
        ValidatorUtils.validateEntity(wxUserInfo);
        wxUserInfoService.updateAllColumnById(wxUserInfo);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] openIds){
        wxUserInfoService.deleteBatchIds(Arrays.asList(openIds));

        return R.ok();
    }

}
